﻿using PureMVC.Interfaces;
using PureMVC.Patterns;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class StartMediator : Mediator
{
    private StartProxy startProxy;
    public StartMediator(StartView startView) : base(NAME, startView)
    {
        
    }

    public StartView StartView
    {
        get { return (StartView)base.ViewComponent; }
    }
    public override void OnRegister()
    {
        base.OnRegister();
        //游戏开始发消息给HitCommand
        StartView.submit += () => { SendNotification(HitSystemEvent.HitCommand,null,"Begin"); };
        StartView.timeSubmit += time => { SendNotification(HitSystemEvent.StartCommand, time, "TimeJJ"); };
        
        StartView.Gameover += score => { SendNotification(HitSystemEvent.StartCommand, score,"GameOver"); };


        startProxy = Facade.RetrieveProxy(StartProxy.NAME) as StartProxy;
        if (null == startProxy)
            throw new Exception(StartProxy.NAME + "is null!");
        StartView.UpdateView(startProxy.num, startProxy.startTime) ;
    }
    public override IList<string> ListNotificationInterests()
    {
        IList<string> notifications = new List<string>();
        notifications.Add(HitSystemEvent.TimeJJ);
        notifications.Add(HitSystemEvent.ScoreAdd);
        notifications.Add(HitSystemEvent.GameOver);
        return notifications;
    }
    public override void HandleNotification(INotification notification)
    {
        switch (notification.Name)
        {
            case HitSystemEvent.TimeJJ:
                int[] a = (int[])notification.Body;
                StartView.UpdateView(a[0],(float)a[1]);
                break;
            case HitSystemEvent.ScoreAdd:
                int[] b = (int[])notification.Body;
                StartView.UpdateView(b[0], (float)b[1]);
                break;
            case HitSystemEvent.GameOver:
                int c=(int)notification.Body;
                StartView.GameOver(c);
                break;
        }
    }
}
